import React, { Component, createContext } from 'react'
import Father from './Father'
import { Provider } from '../utils'

// const { Provider } = createContext()

// Provider  提供数据
// Consumer  使用数据

// 嵌套传值

class GrandFather extends Component {
    state = {
        count: 88888
    }
    render() {
        const { count } = this.state
        return (
            <div>
                <h2>我是爷爷组件 --- {count}</h2>
                {/* 通过Provider包裹要使用数据的组件 */}
                {/* 把要传递的数据通过value属性传递下去 */}
                <Provider value={count}>
                    <Father />
                    <button onClick={() => {
                        this.setState({
                            count: this.state.count += 1
                        })
                    }}>+1</button>
                </Provider>
            </div>
        )
    }
}


export default GrandFather
